<template>
  <div>
    <el-dialog :visible.sync="dialogVisible" lock-scroll width="65%" height="50%">
      <div slot="title" class="header_title">
        <span class="title_span">请选择人员</span>
        <div class="title_search">
          <div>
            <el-input
              @change="onQuery"
              v-model="queryData.queryParam"
              placeholder="请输入人员编号\姓名\拼音码搜索"
            ></el-input>
            <el-button type="primary" @click="onQuery">搜索</el-button>
          </div>
          <div>
            <el-image
              :src="require('@/assets/fullscreen.png')"
              style="width: 23px;height: 23px;"
              @click="onShowColumn()"
            ></el-image>
          </div>
        </div>
      </div>
      <div class="content_div">
        <div class="info_table">
          <div class="div_tree">
            <div class="tree_div1">
              <p>部门类别</p>
            </div>
            <div class="tree_input">
              <p>
                <input type="text" placeholder="查找" v-model="filterText" />
                <span>
                  <i class="el-icon-search"></i>
                </span>
              </p>
            </div>
            <div class="tree_structure">
              <el-tree
                ref="tree"
                :data="treeData"
                node-key="id"
                :props="defaultProps"
                highlight-current
                default-expand-all
                :expand-on-click-node="false"
                @node-click="handleNodeClick"
                :filter-node-method="filterNode"
              ></el-tree>
            </div>
          </div>
          <!-- 右侧列表 -->
          <div class="div_table">
            <div class="table_content">
              <el-table
                :data="tableData.records"
                @row-click="onClickRow"
                @row-dblclick="ondbClickRow"
                :row-class-name="tableRowClassName"
                height="100%"
              >
                <el-table-column :resizable="false" label="序号" type="index" width="50"></el-table-column>
                <el-table-column
                  :show-overflow-tooltip="true"
                  v-for="(item, i) in newColumnData"
                  :key="i"
                  :prop="item.props"
                  :label="item.morenName"
                  min-width="150px"
                ></el-table-column>
              </el-table>
            </div>
            <div class="table_pagination">
              <p class="total_div">共{{ tableData.total }}条</p>
              <div class="pagination_div">
                <el-pagination
                  background
                  @size-change="handleSizeChange"
                  @current-change="handleCurrentChange"
                  :current-page="currentPage"
                  :page-sizes="[20, 50, 100, 200]"
                  :page-size="pagesize"
                  :pager-count="5"
                  layout="jumper, prev, pager,next, sizes"
                  :total="tableData.total"
                ></el-pagination>
              </div>
            </div>
          </div>
        </div>
        <div class="info_button">
          <el-button type="primary" @click="onSelectRow">选择</el-button>
          <el-button @click="onCancelRow">取消</el-button>
        </div>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { mapGetters } from 'vuex'
import { getAction } from '@/api/manage'
// 导入调用处理权限数据方法
import { handleOtherPermissions } from '@/utils/index'
export default {
  name: 'BasicInformation',
  computed: {
    ...mapGetters(['name']),
  },
  created () {
    this.getData()
  },
  data () {
    return {
      companyTypeName: '',
      queryData: {
        queryParam: '',
        deptId: '',
      },
      pagesize: 20, //每页的数据条数
      currentPage: 1, //默认开始页面
      tableData: {},
      newColumnData: [
        {
          morenName: '人员编号',
          props: 'personNo',
        },
        {
          morenName: '姓名',
          props: 'realname',
        },
        {
          morenName: '所在部门',
          props: 'deptName',
        },
        {
          morenName: '职务岗位',
          props: 'postName',
        }
      ],
      treeData: [],
      defaultProps: {
        children: 'children',
        label: 'label',
      },
      selectRow: {}, //当前选择的数据
      dialogVisible: false, // 新增弹框
      fullScreen: false,
      filterText: ''
    }
  },
  watch: {
    filterText (val) {
      this.$refs.tree.filter(val);
    }
  },
  methods: {
    filterNode (value, data) {
      if (!value) return true;
      return data.label.indexOf(value) !== -1;
    },
    tableRowClassName ({ row }) {
      if (row.id === this.selectRow.id) {
        return 'select_row'
      }
    },
    // 获取数据
    getData () {
      Object.assign(this.$data, this.$options.data())
      this.getTreeData()
      this.getTableData()
    },
    // 获取 部门类别 树形菜单
    getTreeData () {
      getAction('/dept/xghAccountBookDept/buildDeptTree', {}).then((res) => {
        if (res.code === 200) {
          this.treeData = res.result
        }
      })
    },
    // 获取表格数据
    getTableData (page) {
      let data = {
        ...this.queryData,
        pageSize: this.pagesize,
        pageNo: page || 1,
      }
      getAction('/dept/xghAccountBookDept/getDeptUsers', data).then((res) => {
        if (res.code === 200) {
          this.tableData = res.result
          this.tableData.records.forEach((item) => {
            item.status = item.status == 0 ? true : false
          })
        }
      })
    },
    // 搜索
    onQuery () {
      this.getTableData()
    },
    // 全屏显示
    onShowColumn () {
      this.fullScreen = !this.fullScreen
    },
    // 搜索树形结构数据
    onSelectTree () {
      this.getTreeData()
    },
    // 点击树形菜单的节点时，触发此事件查询表格数据
    handleNodeClick (data) {
      if (data.id === "0") {
        this.queryData.deptId = ''
      } else {
        this.queryData.deptId = data.id
      }
      this.nowLabel = data.storehouseName
      this.getTableData()
    },
    // 单击表格中的某一列，选中该列
    onClickRow (row) {
      this.selectRow = row
    },
    // 双击表格中的某一列，除了选中该列之外，还需要把数据回传给父级组件
    ondbClickRow (row) {
      this.selectRow = row
      this.onSelectRow()
    },
    // 数据回传给父级组件
    onSelectRow () {
      var objStr = JSON.stringify(this.selectRow)
      if (objStr == '{}') {
        this.$elMessage.warning('请选择一条信息！')
      } else {
        this.$emit('onSelectStaff', this.selectRow)
        this.dialogVisible = false
        this.selectRow = {}
      }
    },
    // 取消
    onCancelRow () {
      this.$emit('onCancelStorehouse', this.selectRow)
      this.dialogVisible = false
    },
    // 获取每页几条数据
    handleSizeChange (val) {
      this.pagesize = val
      this.getTableData()
    },
    // 获取当前第几页
    handleCurrentChange (val) {
      this.currentPage = val
      this.getTableData(val)
    },
  },
}
</script>

<style lang="scss" scoped>
::v-deep .el-dialog {
  width: 100%;
  .el-dialog__body {
    padding: 0;
  }
  .el-dialog__header {
    width: 100%;
    height: 0.937559rem;
    box-sizing: border-box;
    padding: 0 0.187512rem 0 0.281268rem;
    border-bottom: 1px solid #eeeeee;
    display: flex;
    align-items: center;
    justify-content: space-between;
    .el-dialog__headerbtn {
      position: static;
      .el-icon-close {
        color: #999;
        font-size: 30px;
      }
    }
  }
  .header_title {
    width: 100%;
    display: flex;
    align-items: center;
    .title_span {
      white-space: nowrap;
      font-size: 24px;
      color: #666;
      font-weight: 600;
    }
    .title_search {
      width: 100%;
      display: flex;
      align-items: center;
      justify-content: space-between;
      box-sizing: border-box;
      padding: 0 0.468779rem 0 1.875117rem;
      > div {
        display: flex;
        align-items: center;
        .el-input {
          width: 4.725295rem;
          height: 0.562535rem;
          margin-right: 0.112507rem;
          .el-input__inner {
            height: 0.562535rem;
            border-color: #dddddd;
            box-sizing: border-box;
            padding: 0 0.150009rem;
            background: #fff;
            font-size: 12px;
            color: #666;
            &::placeholder {
              font-size: 12px;
              color: #c1c1c1;
            }
          }
        }
        .el-button {
          width: 1.12507rem;
          height: 0.562535rem;
          text-align: center;
          box-sizing: border-box;
          display: flex;
          align-items: center;
          justify-content: center;
          font-size: 12px;
          border-radius: 0.093756rem;
          border: none;
          margin-right: 0.112507rem;
          span {
            color: #fff;
            font-size: 12px;
            font-weight: normal;
          }
        }
      }
    }
    .set_up {
      font-size: 23px;
      color: rgb(153, 153, 153);
    }
  }
}
.content_div {
  width: 100%;
  height: 60vh;
  background: #fff;
  box-sizing: border-box;
  padding: 0.187512rem 0.281268rem;
  .info_table {
    width: 100%;
    height: calc(100% - 0.750047rem);
    display: flex;
    .div_tree {
      width: 2.812676rem;
      height: calc(100% - 1.12507rem);
      box-sizing: border-box;
      padding: 0.131258rem 0;
      border: 0.018751rem solid #e3e3e3;
      transition: all 0.3s;
      .tree_div1 {
        width: 100%;
        height: 0.337521rem;
        box-sizing: border-box;
        padding: 0 0.168761rem;
        display: flex;
        align-items: center;
        justify-content: space-between;
        p {
          color: #666666;
          font-size: 12px;
        }
      }
      .tree_input {
        width: 100%;
        height: 0.562535rem;
        margin-top: 0.131258rem;
        box-sizing: border-box;
        padding: 0 0.168761rem;
        p {
          width: 100%;
          height: 0.562535rem;
          margin: 0;
          box-sizing: border-box;
          border: 1px solid #dddddd;
          display: flex;
          align-items: center;
          position: relative;
          input {
            width: 100%;
            box-sizing: border-box;
            padding: 0 0.600038rem 0 0.093756rem;
            height: 0.525033rem;
            border: none;
            font-size: 12px;
            &:focus {
              outline: none;
            }
          }
          span {
            position: absolute;
            right: 0;
            display: flex;
            align-items: center;
            justify-content: center;
            width: 0.562535rem;
            height: 0.525033rem;
            background: #fff;
            .el-icon-search {
              font-size: 20px;
              color: rgb(211, 211, 211);
            }
          }
        }
      }
      .tree_structure {
        width: 100%;
        height: calc(100% - 0.337521rem - 0.131258rem - 0.131258rem - 0.562535rem);
        box-sizing: border-box;
        padding: 0 0.168761rem;
        margin-top: 0.131258rem;
        overflow: auto;
        ::v-deep .el-tree {
          width: 100%;
          .el-tree-node__children {
            .el-tree-node__label {
              color: #666;
              font-weight: normal;
            }
          }
          .el-tree-node__label {
            font-size: 12px;
            font-weight: 600;
          }
          .is-current {
            .el-tree-node__content {
              background-color: #e6f7ff;
            }
          }
          .el-tree-node__content > .el-tree-node__expand-icon {
            padding-left: 0;
          }
        }
      }
    }
    .div_table {
      width: calc(100% - 3.000188rem);
      height: 100%;
      margin-left: 0.187512rem;
      display: flex;
      flex-direction: column;
      justify-content: space-between;
      transition: all 0.3s;
      .table_content {
        height: calc(100% - 1.12507rem);
        ::v-deep .el-table {
          border: 1px solid #e3e3e3;
          box-sizing: border-box;
          th,
          td {
            padding: 0;
            color: #666;
            box-sizing: border-box;
            border-right: 1px solid #e3e3e3;
            .cell {
              height: 0.562535rem;
              display: flex;
              align-items: center;
              font-size: 12px;
            }
            &:first-child {
              .cell {
                justify-content: center;
              }
            }

            &:last-child {
              border-right: none;
            }
          }
          th {
            .cell {
              background: #ededed;
              justify-content: center;
            }
          }
          .el-table__body tr:hover > td {
            background: #e3f6ff;
          }
          .el-table__footer-wrapper {
            td {
              background: #f4f4f4;
              border: none;
            }
          }
          //滚动条的宽度
          ::-webkit-scrollbar {
            width: 10px;
            height: 10px;
            background-color: #e5e5e5;
          }
          //滚动条的滑块
          ::-webkit-scrollbar-thumb {
            background-color: #c9c9c9;
          }
        }
      }
      .table_pagination {
        width: 100%;
        height: 1.12507rem;
        box-sizing: border-box;
        padding: 0.168761rem 0;
        display: flex;
        .total_div {
          line-height: 0.787549rem;
          font-size: 12px;
          color: #666;
          margin: 0;
          white-space: nowrap;
        }
        .pagination_div {
          flex: 1;
          display: flex;
          align-items: center;
          justify-content: flex-end;
          ::v-deep .el-pagination {
            padding: 0;
            height: 0.525033rem;
            .el-pagination__sizes {
              margin: 0;
              .el-input {
                margin-right: 0;
              }
            }
          }
        }
      }
    }
  }
  .info_button {
    width: 100%;
    height: 0.750047rem;
    display: flex;
    justify-content: flex-end;
    ::v-deep .el-button {
      width: 1.12507rem;
      height: 0.562535rem;
      display: flex;
      justify-content: center;
      align-items: center;
      border-radius: 0.093756rem;
    }
  }
}
::v-deep .select_row {
  background-color: #e3f6ff !important;
}
</style>